//
//  LCCheckToolViewController.m
//  AliyunPlayerMediaDemo
//
//  Created by 王凯 on 2017/8/26.
//  Copyright © 2017年 com.alibaba.ALPlayerVodSDK. All rights reserved.
//

#import "LCCheckToolViewController.h"
#import <ShareSDK/ShareSDK.h>

#define CHECTTOOLURL @"https://player.alicdn.com/detection.html?from=iOS"

@interface LCCheckToolViewController ()
@end

@implementation LCCheckToolViewController

#pragma mark - naviBar
- (void)loadView {
    [super loadView];
    self.link = [NSString stringWithFormat:@"%@&source=%@",CHECTTOOLURL,self.playUrlPath];
    NSLog(@"self.link = %@", self.link);
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"诊断工具";
    [self initWebView];
    [self setupRightBarButtonItem];
}

- (void)initWebView{
    NSMutableString *javascript = [NSMutableString string];
    [javascript appendString:[NSString stringWithFormat:@"var bottomTag = document.getElementsByClassName('ui-tab-nav ui-border-b')[0];bottomTag.parentNode.removeChild(bottomTag);"]];
    [javascript appendString:[NSString stringWithFormat:@"var bottomTag = document.getElementsByClassName('ui-form-item  ui-form-item-show  ui-border-b')[0];bottomTag.parentNode.removeChild(bottomTag);"]];
    [javascript appendString:[NSString stringWithFormat:@"var bottomTag = document.getElementsByClassName('ui-form-item  ui-form-item-show  ui-border-b')[0];bottomTag.parentNode.removeChild(bottomTag);"]];

    WKUserScript *userScript = [[WKUserScript alloc] initWithSource:javascript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
    [self.webView.configuration.userContentController addUserScript:userScript];

    @weakify(self)
    self.shouldStartLoadBlock = ^(NSString *url) {
        NSLog(@"url = %@", url);
        @strongify(self)
        self.isLoad = YES;
    };
    
}
- (void)getHtmlTitle:(NSString *)title {
    self.title = @"诊断工具";
}

- (void)setupRightBarButtonItem {
    if ([ShareSDK isClientInstalled:SSDKPlatformTypeQQ] == YES) {
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"点点点"] style:UIBarButtonItemStylePlain target:self action:@selector(rightBtnClick)];
    }
}

- (void)rightBtnClick
{
    ACActionSheet *actionSheet = [[ACActionSheet alloc] initWithTitle:@"" cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@[@"QQ客服"] actionSheetBlock:^(NSInteger buttonIndex) {
        //            NSLog(@"ACActionSheet block - %ld",buttonIndex);
        if (buttonIndex == 0) {
            //用来接收临时消息的客服QQ号码(注意此QQ号需开通QQ推广功能,否则陌生人向他发送消息会失败)
            NSString *QQ = @"1211734366";
            //调用QQ客户端,发起QQ临时会话
            NSString *url = [NSString stringWithFormat:@"mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web",QQ];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
        }
    }];
    [actionSheet show];
}

@end
